<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!--#include file="../../../inc/conn.asp"-->
<!--#include file="../common/u.asp"-->
<%links="order"%>
<%
urlid=checkstr(inHTML(request("id")))
if urlid=""  then
response.Write("<script>window.location.href='/';</script>")
response.End()
else 
set rs=server.CreateObject("adodb.recordset")
sql="select * from orderlist where [order]='"&urlid&"'"
rs.open sql,conn,1,1
if rs.eof and rs.bof then
response.Write("<script>window.location.href='/';</script>")
response.End
else
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>代购订单</title>
<link href="favicon.ico" rel="shortcut icon" type="image/x-icon"/>
<link rel="stylesheet" type="text/css" href="/css/style.css" />
<script type="text/javascript" src="/js/jquery.min.js"></script>
<script type="text/javascript">function changeNum(obj,num){    var input = getParent(obj).getElementsByTagName("input");    for(var i=0;i<input.length;i++)    {        if(input[i].type=="text")        {            if(input[i].value == "")                
input[i].value = num;            
else   

             
input[i].value = input[i].value - 0 + num;   

if (input[i].value<1){
input[i].value=1
}
}    } }
//获取父级对像
function getParent(obj){    if(typeof(obj) != "object"){obj = document.getElementById(obj);}    if(obj)        return obj.parentElement || obj.parentNode;}
</script>
</head>
<body>

<!--#include file="../../common/top.asp"-->




<div class="fullwidth">
	<div class="place ">
		<a href="/">首页</a> &gt; <a href="/user">会员中心</a> &gt; 代购订单
	</div>
</div>
<!--main-->
<div class="fullwidth bg1">
	<div class="main">
		<form action="" name="formreg" method="post">
		
        
        <!--#include file="../common/left.asp"-->
        
        
		
		<div class="right_show f_r">
			<div class="title_4">
				<h2>代购修改</h2><div></div>
			</div>
			<div class="clear20"></div>
			<table class="stable">
				<tr class="str">
					<th colspan="2" class="th_1">商品名</th>
					<th class="th_2">商品单价</th>
					<th class="th_2">数量</th>
					<th class="th_3" style="width:87px;">日本国内运费</th>
					<th class="th_5">备注</th>
					<th class="th_4">总价格</th>				
				</tr>
                
                
                <%
					set rslist=server.CreateObject("adodb.recordset")
					sql="select * from orderdetail where [order]='"&rs("order")&"'"
					rslist.open sql,conn,1,3
					if not rslist.eof then
					do while not rslist.eof
					   set rsSource=conn.execute("select * from Source where id="&rslist("sid")&"") '来源
					   set rsShop=conn.execute("select * from Shop where sid="&rslist("sid")&"") '店铺
					   set rsproduct=conn.execute("select * from product where pid="&rslist("pid")&"") '产品
					%>
				<tr>
					<td>
						<br /><img src="<%=rsproduct("pic")%>" width="80" height="80" alt="">
					</td>
					<td style="text-align:left"><a href="/shopping/<%=rsproduct("pid")%>.html"><%=rslist("title")%></a><br /><a><%if rsShop("typeid")="0" then response.Write "实体店" else response.Write "购物网"%>-<%=rsShop("address")%>-<%=rsShop("title")%></a></td>
					<td><%=rsSource("price")%></td>
					<td>
						<span class="s_add" onClick="changeNum(this,-1)">-</span><input name="qty<%=rslist("id")%>" type="text" value="<%=rslist("qty")%>" class="s_c_value" onFocus="if (value =='1'){value =''}" onBlur="if (value ==''){value='1'} if (value =='0'){value='1'}" onkeyup="value=value.replace(/[^\d]/g, '') "  onbeforepaste= "clipboardData.setData( 'text',clipboardData.getData( 'text').replace(/[^\d]/g, ''))"/><span class="s_add" onClick="changeNum(this,1)">+</span>
					</td>
					<td><%=rsSource("transCost")%>日元
                    <%transCost=transCost+cdbl(rsSource("transCost"))%>
                    </td>
					<td><textarea name="content<%=rslist("id")%>"><%=rslist("content")%></textarea></td>
					<td><%=(cdbl(rslist("qty"))*cdbl(rsSource("price")))+cdbl(rsSource("transCost"))%>日元
                    
                    <%tomoney=tomoney+(cdbl(rslist("qty"))*cdbl(rsSource("price")))%>
                    
                     <a href="javascript:formreg.action='?del=<%=rslist("id")%>';formreg.submit()" class="del">删除</a>
                    
                    <input type="hidden" name="cid" value="<%=rslist("id")%>" />
                    </td>
				</tr>
                <%
					   set rsproduct=nothing
					   set rsShop=nothing
					   set rsSource=nothing
					rslist.movenext
					loop
					rslist.close
					set rslist=nothing
					end if		 
					%> 
                    
                    
                    
				
			</table>
      <div class="clear20"></div>
			<table class="stable stable_1">
				<tr>
					<td class="select_td">有缺货商品存在的时候</td>
					<td><label for="nobuy"><input name="Canlackpro" type="checkbox" id="nobuy" <%if rs("Canlackpro")=false then response.Write " checked"%> value="0" /> 有缺货就全部不需要购买</label></td>
				</tr>
			</table>
			
			<div class="clear20"></div>
			<table class="stable stable_1">
				<tr>
					<td class="select_td_1 select_td_norborder">费用一览</td>
					<td class="gray select_td_nolborder" ></td>
				</tr>
				<tr>
					<td class="select_td_1">商品总费用</td>
					<td><%=formatNumber((cdbl(tomoney)+cdbl(transCost))*CDBL(web_rate),0)%>RMB (<%=formatNumber(cdbl(tomoney)+cdbl(transCost),0)%>日元)</td>
				</tr>
				<tr>
					<td class="select_td_1">代购服务费</td>
					<td>
					<%
					  set rsu=server.CreateObject("adodb.recordset")
					  sql="select * from ServiceCost"
					  rsu.open sql,conn,1,3
					  if not rsu.eof then
					  do while not rsu.eof
					  
					
					'计算服务费
					if cdbl(tomoney)>cdbl(rsu("StartMoney")) and cdbl(tomoney)<=cdbl(rsu("EndMoney")) then servicemoneyrate=rsu("rate")
					
					  rsu.movenext
					  loop
					  rsu.close
					  set rsu=nothing
					  end if	
					  response.Write formatNumber(((cdbl(tomoney)+cdbl(transCost))*(cdbl(servicemoneyrate)/100))*cdbl(web_rate),0)&"RMB ("&formatNumber((cdbl(tomoney)+cdbl(transCost))*(cdbl(servicemoneyrate)/100),0)&"日元)"
					  %>
                    </td>
				</tr>
				<tr>
					<td class="select_td_1">总费用</td>
					<td><font class="red"><%=formatNumber((cdbl(tomoney)+cdbl(transCost)+((cdbl(tomoney)+cdbl(transCost))*(cdbl(servicemoneyrate)/100)))*CDBL(web_rate),0)%>RMB (<%=formatNumber(cdbl(tomoney)+cdbl(transCost)+((cdbl(tomoney)+cdbl(transCost))*(cdbl(servicemoneyrate)/100)),0)%>日元)</font></td>
				</tr>
			</table>
			<div class="clear20"></div>
			<div class="clear20"></div>
			
			<div class="sure_btn sure_btn_1">
				<a href="javascript:void(0);" onclick="formreg.submit()" class="success_btn">完成修改</a>
                <a href="/user/order/detail/<%=rs("order")%>" class="success_btn">返回详情</a>
                <input type="hidden" name="t" value="y" />
			</div>
			
			<div class="clear20"></div>
			<div class="clear20"></div>
			
			
		</div>
		
	</form>	
	</div>
</div>

<div class="clear"></div>



<!--#include file="../../common/footer.asp"-->

<%
if request.Form("t")="y" then

Canlackpro=request.Form("Canlackpro")
if Canlackpro="" then Canlackpro=1

if request.Form("cid")="" then
response.write"<script>alert('请取消该订单，再重新生成订单');</script>"
response.write"<script>window.location.href='/user/order/detail/"&rs("order")&"';</script>"
response.end
end if



'删除产品
if request.QueryString("del")<>"" then
  conn.execute("delete from orderdetail where uid='"&uid&"' and id="&request.QueryString("del")&"")
else
  '删除产品不执行这句
  Proid=replace(request.Form("cid")," ","")
  Proid=split(Proid,",")
  for i=0 to ubound(Proid)
		set rsx=server.createobject("adodb.recordset")
		sql="select * from orderdetail where uid='"&uid&"' and id="&Proid(i)&""
		rsx.open sql,conn,1,3
		rsx("qty")=request.Form("qty"&Proid(i))
		rsx("content")=request.Form("content"&Proid(i))
		rsx.update
		rsx.close
		set rsx=nothing
  next
end if



'读取购物车信息
set rslistx=server.CreateObject("adodb.recordset")
sql="select * from orderdetail where uid='"&uid&"' and [order]='"&rs("order")&"'"
rslistx.open sql,conn,1,3
if not rslistx.eof then
do while not rslistx.eof

                       set rsSource=conn.execute("select * from Source where id="&rslistx("sid")&"") '来源
					   set rsShop=conn.execute("select * from Shop where sid="&rsSource("sid")&"") '店铺
					   set rsproduct=conn.execute("select * from product where pid="&rsSource("pid")&"") '产品


'订单产品写入
	  Set rsdetail=server.createobject("adodb.recordset")
	  rsdetail.Open "select * from OrderDetail where id="&rslistx("id")&"" ,conn,2,3
	 ' rsdetail.AddNew 
	  'rsdetail("order")=inBillNo  '订单编号
	  'rsdetail("uid")=request.Cookies("u")("uid")  '会员ID
	  rsdetail("Sid")=rslistx("sid") '来源ID
	  rsdetail("title")=rsproduct("title") '产品名称
	  rsdetail("url")=rsSource("url") '产品图片
	  rsdetail("weight")=rsproduct("weight") '产品链接
	  rsdetail("price")=rsSource("price") '产品价格
	  rsdetail("transCost")=rsSource("transCost") '日本国内运费
	  'rsdetail("Qty")=rslistx("qty") '数量
	  'rsdetail("Content")=rslistx("Content") '备注
	  rsdetail("Type")=0 '类型
	  rsdetail("mark")=1 '默认
	  rsdetail.Update
	  rsdetail.close
	  set rsdetail=nothing

	  
	  '计算商品费
	  tomoney2=tomoney2+(cdbl(rslistx("qty"))*cdbl(rsSource("price")))
	  
	  '计算物流费用
	  transCost2=transCost2+cdbl(rsSource("transCost"))
	  
	                   set rsproduct=nothing
					   set rsShop=nothing
					   set rsSource=nothing
	   
rslistx.movenext
loop
rslistx.close
set rslistx=nothing
end if
'订单产品信息写入完成




                      '计算服务费
					  set rsu=server.CreateObject("adodb.recordset")
					  sql="select * from ServiceCost"
					  rsu.open sql,conn,1,3
					  if not rsu.eof then
					  do while not rsu.eof
					  
					
					  '计算服务费
					  if cdbl(tomoney2)>cdbl(rsu("StartMoney")) and cdbl(tomoney2)<=cdbl(rsu("EndMoney")) then servicemoneyrate2=rsu("rate")
					
					  rsu.movenext
					  loop
					  rsu.close
					  set rsu=nothing
					  end if		



'订单列表信息写入
Set rsadd=server.createobject("adodb.recordset")
rsadd.Open "select * from OrderList where [order]='"&rs("order")&"'" ,conn,2,3
'rsadd.AddNew 
'rsadd("order")=inBillNo '订单号
'rsadd("uid")=request.Cookies("u")("uid") '会员id
rsadd("Money")=formatNumber(cdbl(tomoney2)+cdbl(transCost2)+((cdbl(tomoney2)+cdbl(transCost2))*(cdbl(servicemoneyrate2)/100)),2,-1) '订单总金额
rsadd("Promoney")=formatNumber(cdbl(tomoney2)+cdbl(transCost2),2,-1) '商品总金额
rsadd("ServiceCost")=formatNumber((cdbl(tomoney2)+cdbl(transCost2))*(cdbl(servicemoneyrate2)/100),2,-1) '服务费
rsadd("Canlackpro")=Canlackpro '是否可以缺货
rsadd("Rate")=web_rate '汇率
rsadd.Update
rsadd.close
set rsadd=nothing
'订单列表信息写入完成



response.Redirect "/user/order/detail/"&rs("order")&""

end if








%>

<%
end if
rs.close
set rs=nothing
end if
%>
</body>
</html>